package com.freight.user.serviceimpl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.freight.core.common.utils.ObjectUtil;
import com.freight.core.common.utils.SecurityUtil;
import com.freight.core.entity.User;
import com.freight.user.dto.DriverDto;
import com.freight.user.entity.*;
import com.freight.user.mapper.DriverVoMapper;
import com.freight.user.service.IDriverVoService;
import com.freight.user.service.IdCardService;
import com.freight.user.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 司机详情信息接口实现
 *
 * @author huyingtai
 */
@Slf4j
@Service
public class IDriverVoServiceImpl extends ServiceImpl<DriverVoMapper, UserVo> implements IDriverVoService {

    @Autowired
    SecurityUtil securityUtil;

    @Autowired
    private DriverVoMapper driverVoMapper;

    @Autowired
    private IdCardService idCardService;


    @Override
    public CarrierDriverVo getCarrierDriverVo(Long userId) {

        DriverUser driverUser = driverVoMapper.getDriverVoUserId(userId);

        CarrierDriverVo carrierDriverVo=new CarrierDriverVo();
        if(driverUser!=null){
            if(driverUser.getIdCardId()!=null){
                IdCard idCard=idCardService.get(driverUser.getIdCardId());
                IdCardVo idCardVo=new IdCardVo();
                ObjectUtil.copyPropertiesIgnoreNull(idCard,idCardVo);
                carrierDriverVo.setIdCardVo(idCardVo);
            }



        }

        return carrierDriverVo;
    }

    @Override
    public Page<MsgConsultingListVo> complaintList(Page<MsgConsultingListVo> page, Long userId) {

        return driverVoMapper.complaintList(page,userId);
    }

    @Override
    public DriverInformationVo getDriverInformation(Long userId) {

        DriverInformationVo driverInformationVo=driverVoMapper.getDriverInformation(userId);

        return driverInformationVo;

    }

    @Override
    public List<ManageUserVo> getManageUserIdUser(String mobile) {
        if(mobile==null || mobile.trim().equals("")){
            return new ArrayList<ManageUserVo>();
        }else {
            return driverVoMapper.getManageUserIdUser(mobile);
        }

    }

    @Override
    public AppointDriverInfoVo getAppointDriverInfoByUserId(Long userId) {
        return driverVoMapper.getAppointDriverInfoByUserId(userId);
    }

    @Override
    public List<AppointDriverInfoVo> getAppointDriverInfoByUserIds(Long[] userIds) {
        return driverVoMapper.getAppointDriverInfoByUserIds(userIds);
    }


    @Override
    public HashMap<Long, AppointDriverInfoVo> getAppointDriverInfoMapByUserIds(Long[] userIds) {
        List<AppointDriverInfoVo> res = getAppointDriverInfoByUserIds(userIds);
        HashMap<Long, AppointDriverInfoVo> ress = new HashMap<>();
        for (AppointDriverInfoVo re : res) {
            ress.put(re.getUserId(), re);
        }
        return ress;
    }

    @Override
    public DriverVo getDriverVoByUserId(Long userId) {
        return driverVoMapper.getDriverVoByUserId(userId);
    }

    @Override
    public List<DriverVo> getDriverVoByUserIds(Long[] userIds) {
        return driverVoMapper.getDriverVoByUserIds(userIds);
    }

    @Override
    public Page<DriverDetailInfoVo> getDriverInfo(Page<DriverDetailInfoVo> page, DriverDto driverDto) {

        List<DriverDetailInfoVo> driverInfo = driverVoMapper.getDriverInfo(page, driverDto).getRecords();

        //放入分页
        Page<DriverDetailInfoVo> driverDetailInfoVoPage = page.setRecords(driverInfo);

        return driverDetailInfoVoPage;
    }

    @Override
    public Page<DriverDetailInfoVo> getCompanyDriverInfo(Page<DriverDetailInfoVo> page, DriverDto driverDto) {
        User u = securityUtil.getCurrUser();

        List<DriverDetailInfoVo> driverInfo = driverVoMapper.getCompanyDriverInfo(page, driverDto,u.getId()).getRecords();

        //放入分页
        Page<DriverDetailInfoVo> driverDetailInfoVoPage = page.setRecords(driverInfo);

        return driverDetailInfoVoPage;
    }

    @Override
    public List<DriverDetailInfoVo> getDriverInfo(DriverDto driverDto) {
        return driverVoMapper.getDriverInfo(driverDto);
    }

    @Override
    public List<DriverInfoVo> getDriverBaseInfo(DriverDto driverDto) {
        return driverVoMapper.getDriverBaseInfo(driverDto);
    }

    @Override
    public DriverInfoVo getDriverInfoByUserId(Long userId) {

        return driverVoMapper.getDriverInfoByUserId(userId);
    }

    @Override
    public List<DriverInfoVo> getDriverInfoByUserIds(Long[] userIds) {
        return driverVoMapper.getDriverInfoByUserIds(userIds);
    }

}